<?php
/**
 * Created by PhpStorm.
 * User: serenehaly
 * Date: 2018/2/2
 * Time: 16:02
 */

namespace app\api\validate;


class IDCollection extends BaseValidate
{
    protected $rule = [
        'ids' => 'require|checkIDs'
    ];

    protected $message = [
        'ids' => 'ids必须是以正整数开头，以逗号拼接的一个或多个正整数'
    ];

    protected function checkIDs($value)
    {
        $values =explode(',', $value);

        if (empty($values)) {
            return false;
        } else {
            foreach ($values as $id) {
                if (!$this->isPositiveInteger($id)) {
                    return false;
                } else {
                    return true;
                }
            }
        }
    }
}